package ca.tatham.senssim.diffusion;

import ca.tatham.senssim.AbstractPacket;
import ca.tatham.senssim.SensorType;
import ca.tatham.senssim.Simulation;
import ca.tatham.senssim.pddd.Level;
import ca.tatham.senssim.util.Address;
import ca.tatham.senssim.util.Region;

public class InterestMessage extends AbstractPacket
{
  private final Interest m_interest;
  private final int m_startTime;
  private Level m_level;

  public InterestMessage(Address source, Address destination, Interest interest)
  {
    super(source, destination, source);
    m_interest = interest;
    m_startTime = Simulation.getTime();
  }

  public InterestMessage(InterestMessage packet, Address newSource,
      Address newDestination)
  {
    super(newSource, newDestination, packet.getSinkAddress(), packet
        .getSequence());
    m_startTime = packet.getStartTime();
    m_interest = packet.getInterest();
  }

  public int getStartTime()
  {
    return m_startTime;
  }

  public Interest getInterest()
  {
    return m_interest;
  }

  public void setLevel(Level level)
  {
    m_level = level;
  }

  public Level getLevel()
  {
    return m_level;
  }

  public int getSize()
  {
    return 64;
  }

  public static class Interest
  {
    public final SensorType type;
    public final int interval;
    public final int duration;
    public final Region region;

    public Interest(SensorType atype, int ainterval, int aduration,
        Region aregion)
    {
      type = atype;
      interval = ainterval;
      duration = aduration;
      region = aregion;
    }

    @Override
    public boolean equals(Object obj)
    {
      Interest that = (Interest) obj;
      return this.type.equals(that.type) && this.interval == that.interval
          && this.duration == that.duration;
    }
  }
}
